﻿// Copyright (C) Norsolutions GmbH
// All rights reserved.
// For conditions of distribution and use, see license.
// Created by: Reng van Oord
// Created:    2010.05.05


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;


/// <summary>
///This class can be used as a base for page output filters.
///Page output filters can be used to directly modify the HTML that is sent to the browser.
///Filters can be chained together like this: 
///    Page.Filter = MyFilter(Page.Filter)
///    Page.Filter = MySecondFilter(Page.Filter)
///    
/// In ASP.Net MVC, [actionContext.]HttpContext.Response.Filter can typically be set (instead of Page.Filter).
///
///Filters that are chained earlier in the code actually handle the output later when the page is rendered.
///To implement a filter, simply override the Write method and add a constructor
/// </summary>
public abstract class OutputFilterBase : Stream
{
    protected Stream _sink;

    public OutputFilterBase(Stream stream)
        : base()
    {
        _sink = stream;
    }



    public override bool CanRead
    {
        get { return _sink.CanRead; }
    }

    public override bool CanSeek
    {
        get { return _sink.CanSeek; }
    }

    public override bool CanWrite
    {
        get { return _sink.CanWrite; }
    }

    public override void Flush()
    {
        _sink.Flush();
    }

    public override long Length
    {
        get { return _sink.Length; }
    }

    public override long Position
    {
        get
        {
            return _sink.Position;
        }
        set
        {
            _sink.Position = value;
        }
    }

    public override int Read(byte[] buffer, int offset, int count)
    {
        return _sink.Read(buffer, offset, count);
    }

    public override long Seek(long offset, SeekOrigin origin)
    {
        return _sink.Seek(offset, origin);
    }

    public override void SetLength(long value)
    {
        _sink.SetLength(value);
    }
}